home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Magazine / ActiveARexx / NetPBM / src / deep2ppm.asm < prev    next >
Encoding:
Assembly Source File  |  1995-12-18  |  5.4 KB  |  217 lines

  1. ; Convert DEEP-IFF nach PPM
  2. ; Gerd Wieczorek, 16.12.95
  3.  
  4.  
  5. buflen          equ     1024
  6.  
  7. dosbase         equ     0               ; long
  8. rdarg           equ     4+dosbase
  9. arg_file        equ     4+rdarg
  10. breite          equ     4+arg_file
  11. hoehe           equ     4+breite
  12. buffer1         equ     4+hoehe
  13. buffer2         equ     buflen+buffer1
  14. gesamt          equ     buflen+buffer2
  15.  
  16.         nolist
  17.         machine 68000
  18.         INCDIR  "ass:/INCLUDE"
  19.         INCLUDE "lvo/exec.i"
  20.         INCLUDE "lvo/dos.i"
  21.         INCLUDE "dos/dos.i"
  22.         list
  23.  
  24. r_memptr    equr    a5
  25. r_buf1ptr   equr    a4
  26. r_chunk     equr    a3
  27. r_retval    equr    d7
  28. r_fh1       equr    d6
  29. r_fh2       equr    d5
  30.  
  31. CALL    macro
  32.         jsr     _LVO\1(a6)
  33.         endm
  34.  
  35. start
  36.         move.l  4.w,a6
  37.         move.l  #gesamt,d0
  38.         moveq   #1,d1
  39.         swap    d1              ; MEMF_CLEAR
  40.         CALL    AllocVec
  41.         tst.l   d0
  42.         bne.s   mem_ok
  43.         moveq   #30,d0
  44.         rts
  45. mem_ok
  46.         move.l  d0,r_memptr     ; Pointer auf reserviertes RAM
  47.         moveq   #25,r_retval    ; RetVal setzen
  48.         lea     dosname(pc),a1
  49.         moveq   #37,d0
  50.         CALL    OpenLibrary
  51.         move.l  d0,(r_memptr)   ; dosbase
  52.         bne.s   dos_ok
  53.         bra     free_mem
  54. dos_ok
  55.         move.l  d0,a6
  56.         moveq   #20,r_retval
  57.         lea     buffer1(r_memptr),r_buf1ptr ; globale Konstanten
  58.         lea     chunks(pc),r_chunk
  59. arg
  60.         lea     argstring(pc),a0
  61.         move.l  a0,d1           ; Argument-Schablone nach d1
  62.         lea     arg_file(r_memptr),a0
  63.         move.l  a0,d2           ; Argument-Struct nach d2
  64.         moveq   #0,d3
  65.         CALL    ReadArgs
  66.         move.l  d0,rdarg(r_memptr)
  67.         bne.s   arg_ok
  68.  
  69.         CALL    IoErr           ; Fehler bei ReadArgs
  70.         move.l  d0,d1
  71.         moveq   #0,d2
  72.         CALL    PrintFault
  73.         bra.s   close_dos
  74. arg_ok
  75.         moveq   #10,r_retval
  76.         move.l  arg_file(r_memptr),d1
  77.         move.l  #MODE_OLDFILE,d2
  78.         CALL    Open
  79.         move.l  d0,r_fh1
  80.         beq.s   free_arg
  81.  
  82.         move.l  r_fh1,d1
  83.         move.l  r_buf1ptr,d2
  84.         moveq   #12,d3          ; 12 Byte Header
  85.         CALL    Read
  86.         tst.l   d0              ; überhaupt gelesen ?
  87.         beq.s   close_file
  88.  
  89.         move.l  (r_chunk)+,d0   ; "FORM"
  90.         cmp.l   (r_buf1ptr),d0
  91.         bne.s   close_file
  92.         move.l  (r_chunk)+,d0   ; "DEEP"
  93.         cmp.l   8(r_buf1ptr),d0
  94.         bne.s   close_file
  95.  
  96.         move.l  (r_chunk)+,d4   ; "DGBL"
  97.         bsr.s   SeekChunk
  98.         beq.s   close_file
  99.  
  100.         move.l  r_fh1,d1
  101.         move.l  r_buf1ptr,d2
  102.         move.l  4(r_buf1ptr),d3 ; Länge DGBL-Chunk
  103.         CALL    Read
  104.         tst.l   d0
  105.         beq.s   close_file
  106.  
  107.         move.w  (r_buf1ptr),breite+2(r_memptr)  ; Word -> LW
  108.         move.w  2(r_buf1ptr),hoehe+2(r_memptr)  ; Word -> LW
  109.  
  110.         move.l  (r_chunk)+,d4   ; "DBOD"
  111.         bsr.s   SeekChunk
  112.         beq.s   close_file
  113.  
  114.         CALL    Output          ; StdOut holen
  115.         move.l  d0,r_fh2
  116.         beq.s   close_file
  117.  
  118.         bsr.s   Header          ; PNM-Header schreiben
  119.         beq.s   close_file
  120.         bsr.s   Deep2pnm        ; eigentliche Wandlung
  121.  
  122.         moveq   #0,r_retval     ; alles ok
  123. close_file
  124.         move.l  r_fh1,d1
  125.         CALL    Close
  126. free_arg
  127.         move.l  rdarg(r_memptr),d1
  128.         CALL    FreeArgs
  129. close_dos
  130.         move.l  a6,a1           ; dosbase
  131.         move.l  4.w,a6
  132.         CALL    CloseLibrary
  133. free_mem
  134.         move.l  r_memptr,a1
  135.         CALL    FreeVec
  136. ende
  137.         move.l  r_retval,d0
  138.         rts
  139.  
  140. SeekChunk
  141.         move.l  r_fh1,d1
  142.         move.l  r_buf1ptr,d2
  143.         moveq   #8,d3
  144.         CALL    Read
  145.         tst.l   d0
  146.         beq.s   end_seek
  147.  
  148.         move.l  d4,d0
  149.         cmp.l   (r_buf1ptr),d0
  150.         beq.s   end_seek
  151.  
  152.         move.l  r_fh1,d1
  153.         move.l  4(r_buf1ptr),d2
  154.         moveq   #OFFSET_CURRENT,d3
  155.         CALL    Seek
  156.         bra.s   SeekChunk
  157. end_seek
  158.         tst.l   d0              ; CC setzen: 0 = Fehler bei Read, sonst ok
  159.         rts
  160.  
  161. Deep2pnm
  162.         move.l  r_fh1,d1
  163.         move.l  r_buf1ptr,d2
  164.         move.l  #buflen,d3      ; Buffer voll lesen
  165.         CALL    Read
  166.         tst.l   d0
  167.         beq.s   conv_end
  168.  
  169.         move.l  r_buf1ptr,a0
  170.         lea     buffer2(r_memptr),a1
  171.         move.l  a1,d2           ; für Write merken
  172.         lsr.l   #2,d0           ; Anzahl Langworte
  173.         move.l  d0,d3           ; merken
  174.         subq.l  #1,d0
  175. copyloop
  176.         move.b  (a0)+,(a1)+     ; je 3 von 4 Byte kopieren
  177.         move.b  (a0)+,(a1)+
  178.         move.b  (a0)+,(a1)+
  179.         addq.l  #1,a0
  180.         dbra    d0,copyloop
  181.  
  182.         move.l  r_fh2,d1
  183.         mulu    #3,d3           ; 3 Byte je Langwort schreiben
  184.         CALL    Write
  185.         bne.s   Deep2pnm
  186. conv_end
  187.         rts
  188.  
  189. Header
  190.         move.l  4.w,a6
  191.         lea     fmtstring(pc),a0
  192.         lea     breite(r_memptr),a1
  193.         lea     PutChProc(pc),a2
  194.         move.l  r_buf1ptr,a3
  195.         CALL    RawDoFmt
  196.         move.l  r_fh2,d1
  197.         move.l  r_buf1ptr,d2
  198.         move.l  count(pc),d3
  199.         move.l  (r_memptr),a6   ; dosbase
  200.         CALL    Write
  201.         rts
  202. PutChProc
  203.         move.b  d0,(a3)+
  204.         lea     count(pc),a0
  205.         addq.l  #1,(a0)
  206.         rts
  207.  
  208. count           dc.l    -1      ; für Write wegen abschließender 0
  209. chunks          dc.b    "FORM"
  210.                 dc.b    "DEEP"
  211.                 dc.b    "DGBL"
  212.                 dc.b    "DBOD"
  213. dosname         dc.b    "dos.library",0
  214. argstring       dc.b    "DEEPFILE/A",0
  215. fmtstring       dc.b    "P6",10,"%ld %ld",10,"255",10,0
  216.         end
  217.